//
//  SQRefreshView.swift
//  SQRefresh
//
//  Created by 苏强 on 16/12/9.
//  Copyright © 2016年 suqianghotel. All rights reserved.
//

import UIKit




class SQRefreshView: UIView {
    
    var refreshState: SQRefreshState = .normal{
        didSet{
    
            switch refreshState {
            case .normal:
                tipIndicator.stopAnimating()
                tipIndicator.isHidden = true
                
                tipLabel.text = "下拉刷新"
                
                UIView.animate(withDuration: 0.25, animations: { 
                    self.tipIcon.transform = CGAffineTransform.identity
                })
                
                
                tipIcon.isHidden = false
                
            case .willRefresh:
                UIView.animate(withDuration: 0.25, animations: {
                     self.tipIcon.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI))
                })
               
                tipLabel.text = "释放刷新"
                
            case .isRefreshing:
                tipIcon.isHidden = true
                tipIndicator.startAnimating()
                tipIndicator.isHidden = false
                tipLabel.text = "正在刷新"
            
            }
        }
    }
    
    
    class func refreshView() -> SQRefreshView?
    {
        let nib = UINib(nibName: "SQRefreshView", bundle: nil)
            
        let view = nib.instantiate(withOwner: nil, options: nil)[0] as? SQRefreshView
        
        return view
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        tipIndicator.isHidden = true
    
    }
    

    @IBOutlet weak var tipIndicator: UIActivityIndicatorView!

    @IBOutlet weak var tipIcon: UIImageView!

    @IBOutlet weak var tipLabel: UILabel!
    

}
